package com.example.utils;

import java.util.Formatter;
import java.util.Locale;

public class Utils {

    private StringBuilder mFormatBuilder;
    private Formatter mFormatter;

    public Utils(){
        //转换成字符串的时间
        mFormatBuilder = new StringBuilder();
        mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
    }

    /**
     * 把毫秒转换为：1:20:30 这种形式
     * @param timeMs
     * @return
     */
    public String stringForTime(int timeMs){
        int totalSeconds = timeMs / 1000;
        int seconds = totalSeconds % 60;
        int munites = (totalSeconds / 60) % 60;
        int hours = totalSeconds / 3600;

        mFormatBuilder.setLength(0);
        if (hours > 0){
            return mFormatter.format("%d:%02d:%02d",hours,munites,seconds).toString();
        }else {
            return mFormatter.format("%02d:%02d",munites,seconds).toString();
        }

    }

}
